<?php
/**
 * 商户登录
 * @author Administrator
 *
 */
class account extends CControllerBase{
	
	public function login()
	{
		$model = new shopModel();
		
		$shopNum = $model->getShopNum();
		
		if(CCommon::isIE())
		{
			$this->setViewParam("isIE",1);
			$this->setJsBlock("initUserPwd();");
			$this->setJsFile("/js/s_common.js");
		}
		$this->render("merchant/login",array("msg"=>"","m_num"=>$shopNum));
	}
	
	public function code() {
		$c = new CCommon();
		
		$c->code("merchantCode");
	}
	
	public function userLogin(){
		$checkcode = $this->getRequestData('txt_checkcode');
		if (strtolower($_SESSION['merchantCode']) !== strtolower($checkcode)) {
			echo -1;
			exit;
		}
		
		$username = $this->getRequestData("user_name");
		$pwd = $this->getRequestData("pwd");
		$pwd = CCommon::pwdMd5($pwd);

		$model = new shopModel();
		$loginInfo = $model->userLogin($username, $pwd);

		if($loginInfo)
		{
			$first_login = $loginInfo["first_login"];
			unset($loginInfo["first_login"]);
			$_SESSION["merchantInfo"] = $loginInfo;
			if($first_login==1)
			{
				echo 1;
			}else{
				echo 2;
			}
		}
		else{
			echo -2;
		}
		exit;
	}
	
	public function logout()
	{
		unset($_SESSION["merchantInfo"]);
		$this->redirectUrl("/merchant/account/login");
	}

}